package mrusanov.ui.management.staff

import javax.swing.JPanel
import java.util.Date
import mrusanov.team.Club
import net.miginfocom.swing.MigLayout
import mrusanov.ui.{PanelBuilder, CentralPanel}

class StaffPanel(now:Date, club:Club) extends CentralPanel {
  private val columns = 2

  setLayout(new MigLayout("fill"))

  private def addPanel(panel:EmployeePanel) {
    val children = getComponentCount
    val constraint = if (children % columns == columns - 1) "wrap" else ""
    add(panel, constraint)
  }

  val staff = club.clubStaff

  staff.coachesWithOptions.foreach(c => addPanel(new CoachStaffPanel(club, c, now)))
  addPanel(new DoctorStaffPanel(club, staff.doctor, now))
  addPanel(new MarketingManagerStaffPanel(club, staff.marketingManager, now))
  addPanel(new MasseurStaffPanel(club, staff.masseur, now))
  addPanel(new PrManagerStaffPanel(club, staff.prManager, now))
  addPanel(new PsychologistStaffPanel(club, staff.psychologist, now))

  def buildItself(panelBuilder:PanelBuilder) = panelBuilder.staff
}
